$(function () {
    localStorage.removeItem("typeId");
    setproductsFind();
    let typeId=localStorage.getItem("typeFindid");
    if (typeId!=null){
        typeFinds(typeId);
        localStorage.removeItem("typeFindid");
    }
})

function setproductsFind() {
    let da={
        // page:"",
        // casetypeid:"",
    }
    let dataa=myAjax("/page/producatsPage",da,"post");
    let data=dataa.list;
    let html='';
        for (let i=0; i<data.length; i++){
            html +='        <div>\n' +
                '            <div class="navigation" onclick="selectProductById('+data[i].id+')"><img src="'+data[i].imgHref+'"/></div>\n' +
                '            <div class="producttitle">'+data[i].title+'</div>\n' +
                '        </div>';
        }
        $("#productimg").html(html);
}

function selectProductById(id) {
    window.open("../../engineeringDetailed.html","_self");
    localStorage.setItem("productId",id);
}

var i=1;
function productPageN() {
    let typeId=localStorage.getItem("typeId");
    i=++i;
    let da={
        casetypeid:typeId,
        page:i,
    }
    let dataa=myAjax("/page/producatsPage",da,"post");
    let data=dataa.list;
    let number=dataa.number;//总条数
    let page=dataa.pa-1;//页数
    number=Math.ceil(number/6);//算出总共可以跳转的页数
    if (number>page){
        // localStorage.setItem("da",dataa.pa);
        let productsFind = data;
        let html='';
        for (let i=0; i<productsFind.length; i++){
            html +='        <div>\n' +
                '            <div class="navigation" onclick="selectProductById('+productsFind[i].id+')"><img src="'+productsFind[i].imgHref+'"/></div>\n' +
                '            <div class="producttitle">'+productsFind[i].title+'</div>\n' +
                '        </div>';
        }
        $("#productimg").html(html);
    } else {
        i=--i;
    }
}

function productPageF() {
    if (i>1) {
        i =--i;
        let da={
            page:i,
        }
        let dataa=myAjax("/page/producatsPage",da,"post");
        let productsFind=dataa.list;
        let html='';
        for (let i=0; i<productsFind.length; i++){
            html +='        <div>\n' +
                '            <div class="navigation" onclick="selectProductById('+productsFind[i].id+')"><img src="'+productsFind[i].imgHref+'"/></div>\n' +
                '            <div class="producttitle">'+productsFind[i].title+'</div>\n' +
                '        </div>';
        }
        $("#productimg").html(html);
    }
}

function typeFinds(typeIdFind) {
    localStorage.setItem("typeId",typeIdFind);
    let daa={
        casetypeid:typeIdFind,
    }
    let data=myAjax("/page/producatsPage",daa,"post");
    data=data.list;
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '        <div>\n' +
            '            <div class="navigation" onclick="selectProductById('+data[i].id+')"><img src="' + data[i].imgHref + '"/></div>\n' +
            '            <div class="producttitle">' + data[i].title + '</div>\n' +
            '        </div>';
    }
    $("#productimg").html(html);
}